home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / cpp_libs / cool / ge_cool.lha / GE_COOL2.1 / src / examples / section9 / ex9_11.C next >
C/C++ Source or Header  |  1992-05-17  |  3KB  |  56 lines

  1. //
  2. // Copyright (C) 1991 Texas Instruments Incorporated.
  3. //
  4. // Permission is granted to any individual or institution to use, copy, modify,
  5. // and distribute this software, provided that this complete copyright and
  6. // permission notice is maintained, intact, in all copies and supporting
  7. // documentation.
  8. //
  9. // Texas Instruments Incorporated provides this software "as is" without
  10. // express or implied warranty.
  11. //
  12.  
  13. #include <cool/D_Node.h>            // Include node class
  14. #include <cool/N_Tree.h>            // Include n-ary tree class
  15. #include <cool/String.h>            // Include COOL String class
  16.  
  17. #include <cool/Vector.C>
  18. #include <cool/D_Node.C>
  19. #include <cool/N_Tree.C>
  20.  
  21. DECLARE CoolN_Tree<CoolD_Node,CoolString,3>    // Declare tree type
  22.  
  23. IMPLEMENT CoolD_Node<CoolString,3>        // Implement tree type
  24. IMPLEMENT CoolVector<CoolD_Node<CoolString,3>*>
  25. IMPLEMENT CoolN_Tree<CoolD_Node,CoolString,3>    
  26.  
  27.  
  28. int main (void) {
  29.   CoolD_Node<CoolString,3> president (CoolString("President")); // Create president
  30.   CoolN_Tree<CoolD_Node,CoolString,3> org_chart (president);    // Setup top of tree
  31.   CoolD_Node<CoolString,3> sales (CoolString("Sales"));        // Create sales
  32.   CoolD_Node<CoolString,3> service (CoolString("Service"));    // Create service
  33.   CoolD_Node<CoolString,3> finance (CoolString("Finance"));    // Create finance
  34.   CoolD_Node<CoolString,3> legal (CoolString("Legal"));        // Create legal
  35.   president[0] = &sales;                    // Add sales to chart
  36.   president.insert_after(service, 0);                // Add service to chart
  37.   president.insert_after(finance, 1);                // Add finance to chart
  38.   president.insert_after(legal, 2);                // Add legal to chart
  39.   sales[0] = new CoolD_Node<CoolString,3> (CoolString("Domestic")); // Domestic sales
  40.   CoolD_Node<CoolString,3> international (CoolString("International")); // International
  41.   sales.insert_after(international, 0);
  42.   international[0] = new CoolD_Node<CoolString,3> (CoolString("Asia"));
  43.   international.insert_after(*(new CoolD_Node<CoolString,3> (CoolString("Europe"))), 0);
  44.   international.insert_after(*(new CoolD_Node<CoolString,3> (CoolString("Africa"))), 1);
  45.   finance[0] = new CoolD_Node<CoolString,3> (CoolString("Short Term"));
  46.   finance.insert_after(*(new CoolD_Node<CoolString,3> (CoolString("Long Term"))), 0);
  47.   finance.insert_after(*(new CoolD_Node<CoolString,3> (CoolString("Collections"))), 1);
  48.   org_chart.traversal() = PREORDER;        // Set traversal mode
  49.   for (org_chart.reset (); org_chart.next (); ) { // For each node in tree
  50.     for (int i = 0; i < org_chart.current_depth (); i++) // Indent level
  51.       cout << "   ";
  52.     cout << org_chart.value () << "\n";
  53.   }
  54.   return (0);                    // Return success
  55. }
  56.